#include "stdio.h"
#include "string.h"
#include "math.h"

int shu[200];
int bak[200];
int n;

int count()
{
	int i;
	int tot=0;
	for (i=1;i<n;i++)
		tot+=abs(shu[i]-shu[i+1]);
	for (i=1;i<=n;i++)
		tot+=abs(bak[i]-shu[i]);
	return tot;
}
main()
{


	int i,j;

	scanf("%d",&n);
	for (i=1;i<=n;i++) 
	{	
		scanf("%d",&shu[i]);
		bak[i]=shu[i];
	}
	
	for (i=2;i<n;i++) 
	{
		if (shu[i]>shu[i-1] && shu[i]>shu[i+1]) 
		{
			shu[i]=shu[i-1]>shu[i+1] ? shu[i-1]:shu[i+1];
		}
		else if (shu[i]<shu[i-1] && shu[i]<shu[i+1]) 
		{
			shu[i]=shu[i-1]<shu[i+1] ? shu[i-1]:shu[i+1];
		}
	}
	if (n==1) printf("0\n");
	else printf("%d\n",count());
	
	return 0;
}